from google.appengine.ext import db
from google.appengine.api import users
from geo.geomodel import GeoModel
from google.appengine.ext.db import polymodel

# class Category(db.Model):
    # name = db.StringProperty()
    # description = db.TextProperty()

class Restaurant(GeoModel):
    author = db.UserProperty()
    date = db.DateTimeProperty(auto_now_add=True)
    name = db.StringProperty()
    address = db.PostalAddressProperty()
    description = db.TextProperty()
    phone = db.PhoneNumberProperty()
    link = db.LinkProperty()
    
    def _get_latitude(self):
        return self.location.lat if self.location else None

    def _set_latitude(self, lat):
        if not self.location:
            self.location = db.GeoPt('0,0')
        self.location.lat = lat

    latitude = property(_get_latitude, _set_latitude)

    def _get_longitude(self):
        return self.location.lon if self.location else None

    def _set_longitude(self, lon):
        if not self.location:
            self.location = db.GeoPt('0,0')
        self.location.lon = lon

    longitude = property(_get_longitude, _set_longitude)
    
    def validate(self):
        return self.author and self.date and self.name and self.address and self.description

# class Gaillard(db.Model):
    # user = db.UserProperty()
    # address = db.PostalAddressProperty()
    # favorite_address = db.ListProperty(db.PostalAddress)
    # favorite_restaurant = db.ListProperty(db.Key)

class Post(polymodel.PolyModel):
    author = db.UserProperty()
    date = db.DateTimeProperty(auto_now_add=True)

class Comment(Post):    
    message = db.TextProperty()
    price = db.IntegerProperty()
    quality = db.IntegerProperty()
    quantity = db.IntegerProperty()
    
    def validate(self):
        return self.author and self.message and self.price and self.quality and self.quantity


# class Image(Post):
    # picture = db.BlobProperty(default=None)
    # description = db.TextProperty()

